#include "main.h"

void ThreadWord(void*arg)
{

    long num = *((long*)arg);

    cout << " pthread_self(): " << pthread_self() << "  num :" <<num << endl;

    for(long pos = 0; pos < num ;pos++)
    {
        cout << " pthread_self(): " << pthread_self() << "  pos:" <<pos << endl;
        sleep(1);
    }
    
    // delete arg;

}


int main(int argc, char *argv[])
{

/*
    Pool& pool = Pool::GetInstance();

    cout << "============ pool init ============" << endl;
    cout << "pool.Get_Active()" << pool.Get_Active() << endl;
    cout << "pool.Get_TaskCount()" << pool.Get_TaskCount() << endl;
    cout << "pool.Get_MaxTask()" << pool.Get_MaxTask() << endl;
    cout << "pool.Get_MaxThread()" << pool.Get_MaxThread() << endl;
    cout << "pool.Get_MinThread()" << pool.Get_MinThread() << endl;


    pool.Add_Thread(1);
    cout << "============ Add_Thread ============" << endl;
    cout << "pool.Get_Active()" << pool.Get_Active() << endl;
    cout << "pool.Get_TaskCount()" << pool.Get_TaskCount() << endl;
    cout << "pool.Get_MaxTask()" << pool.Get_MaxTask() << endl;
    cout << "pool.Get_MaxThread()" << pool.Get_MaxThread() << endl;
    cout << "pool.Get_MinThread()" << pool.Get_MinThread() << endl;


    //　添加任务

    TaskNode* task;
    // task.do_task = ThreadWord ;

    srand(time(NULL));

    for(int pos = 0; pos < 10; pos++)
    {

        task = new TaskNode;
        task->do_task = ThreadWord;
        task->arg = new long(random()% 20);
        pool.Add_Task(*task);
    }

    cout << "============ Add_Task ============" << endl;
    cout << "pool.Get_Active():" << pool.Get_Active() << endl;
    cout << "pool.Get_TaskCount():" << pool.Get_TaskCount() << endl;
    cout << "pool.Get_MaxTask():" << pool.Get_MaxTask() << endl;
    cout << "pool.Get_MaxThread():" << pool.Get_MaxThread() << endl;
    cout << "pool.Get_MinThread():" << pool.Get_MinThread() << endl;


    pool.Del_Task(5);
    cout << "============ Del_Task ============" << endl;
    cout << "pool.Get_Active():" << pool.Get_Active() << endl;
    cout << "Del_Task:pool.Get_TaskCount():" << pool.Get_TaskCount() << endl;
    cout << "pool.Get_MaxTask():" << pool.Get_MaxTask() << endl;
    cout << "pool.Get_MaxThread():" << pool.Get_MaxThread() << endl;
    cout << "pool.Get_MinThread():" << pool.Get_MinThread() << endl;



    for(;;)
    {   
        cout << "======= count =======" << endl;
        cout << "pool.Get_Active(): " << pool.Get_Active() << endl;
        cout << "pool.Get_TaskCount():" << pool.Get_TaskCount() << endl;
        cout << "pool.Get_MaxTask():" << pool.Get_MaxTask() << endl;
        cout << "pool.Get_MaxThread():" << pool.Get_MaxThread() << endl;
        cout << "pool.Get_MinThread():" << pool.Get_MinThread() << endl;

        // if(pool.Get_TaskCount())
        //     break;

        sleep(5);

    }
*/

    // Epoll& tcp = Epoll::GetInstance();

    // tcp.ListensEvents();


    Tcp tcp;

    tcp.Begin();

    for(;;)
    {
        cout << "tcp server info" << endl; 
        cout << tcp.GetListensEventsCount() << endl;
        cout << tcp.GetTaskCount()  <<  endl;
        cout << tcp.GetThreadCount()  << endl << endl;

        sleep(2);
    }


    return 0;
}


